#include <bits/stdc++.h>
using namespace std;
long long int  max_result(vector<int>& a)
{
    long long int max_num=INT32_MIN,sec_max=INT32_MIN,
            third_max=INT32_MIN,min_num=INT32_MAX,
            min_sec=INT32_MAX;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]>max_num)
        {
            third_max = sec_max;
            sec_max = max_num;
            max_num = a[i];
        }
        else if(a[i]>sec_max)
        {
            third_max = sec_max;
            sec_max = a[i];
        }
        else if(a[i]>third_max)
        {
            third_max = a[i];
        }
        if(a[i]<min_num)
        {
            min_sec = min_num;
            min_num = a[i];
        }
        else if(a[i]<min_sec){
            min_sec = a[i];
        }
    }
    return max(max_num*sec_max*third_max,max_num*min_num*min_sec);
}
int main() {
    int n,i=0;
    vector<int> a;
    cin>>n;
    while(i<n)
    {
        int tmp;
        i++;
        cin>>tmp;
        a.push_back(tmp);
    }
//        vector<int> a = {1,-5,-2,3};
    cout<<max_result(a);
    return 0;
}